function visible_control(state) {
    var obj;
    if (state) {
        document.getElementById('front').style.display = 'none';
        document.getElementById('background').style.display = 'block';
        document.getElementById('content').style.display = 'block';

        obj = document.getElementById('background_img');
        obj.src = "./img/loginPage/background_cov1.jpg";
        obj.style.transform = "scale(1.0)";

        setTimeout("content_ani(true)", 300);
    }
    if (!state) {
        if ((document.getElementById('usr').value).indexOf(' ') !== -1)
            document.getElementById('usr').value = '';
        document.getElementById('pwd').value = '';
        document.getElementById('content').style.display = 'none';
        document.getElementById('background').style.display = 'none';
        document.getElementById('front').style.display = 'block';
        if (document.getElementById('warning').style.display === 'block')
            hidden_warning();

        obj = document.getElementById('background_img');
        obj.src = "./img/loginPage/background.jpg";
        obj.style.transform = "scale(1.1)";

        content_ani(false);
    }
}

function content_ani(state) {
    var obj = document.getElementById('content');
    if (state) {
        obj.style.opacity = "0.9";
    }
    if (!state) {
        obj.style.opacity = "0";
    }
}

function show_warning(str_warning) {
    document.getElementById('warning').innerText = str_warning;
    document.getElementById('warning').style.display = 'block';
}

function hidden_warning() {
    document.getElementById("warning").style.display = 'none';
}

function login() {
    var username = document.getElementById('usr').value;
    var permit = document.getElementById('pwd').value;
    if (username === '' || permit === '') {
        show_warning("密码或用户名不能为空！");
        return;
    }
    var xmlHttp = new XMLHttpRequest();

    var url = "login";
    xmlHttp.open("POST", url, false);
    xmlHttp.setRequestHeader('content-type', "application/x-www-form-urlencoded");

    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState === 4 && xmlHttp.status === 200) {
            var data = eval("(" + xmlHttp.responseText + ")");
            if (data.state === "true")
                window.location.href = data.url;
            if (data.state === "false")
                show_warning("密码错误或用户不存在！");
        }
    };
    xmlHttp.send("username=" + username + "&password=" + permit);
}

function de_blank(id) {
    var x = document.getElementById(id);
    x.value = x.value.replace(/\s+/g, '');
}